// JavaScript Document
var emailRegxp	  =	/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
function validateReg()
{	
	var name = $('#fname');
	var lname = $('#lname');
	var email = $('#email');
	var studentemail = $('#studentemail');	
	var username = $('#username');
	var passwd = $('#passwd');
	var passwd_rem = $('#passwd_rem');	
	var security_code = $('#security_code');
	var term = $('#terms');
	var parent_permission = $('#parent_permission');	
	var mand_flag = 1;
	var errorText = "";
	
	if(name.val() == "") {
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		name.addClass('invalid');
		name.focus();
	}
	else
	{
		name.removeClass('invalid');
	}
	
	if(lname.val() == "") {
		errorText = "Please fill mandatory fields";		
		mand_flag = 0;
		lname.addClass('invalid');
		lname.focus();
	}
	else
	{
		lname.removeClass('invalid');
	}

    if(username.val() == "") {
    	errorText = "Please fill mandatory fields";
		mand_flag = 0;
		username.addClass('invalid');
		username.focus();
	}
	else
	{
		username.removeClass('invalid');
	}

	if(passwd.val() == "") {
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		passwd.addClass('invalid');
		passwd.focus();		
	}
	else
	{
		passwd.removeClass('invalid');
	}
		
	if(passwd_rem.val() == "") {
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		passwd_rem.addClass('invalid');
		passwd_rem.focus();
	}
	else
	{
		passwd_rem.removeClass('invalid');
	}
	
	if(security_code.val() == "") {
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		security_code.addClass('invalid');
		security_code.focus();
	}
	else
	{
		security_code.removeClass('invalid');
	}
	
	if (!term.attr("checked")){
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		$("#sp_terms").addClass('invalid');
		term.focus();
	}
	else
	{
		$("#sp_terms").removeClass('invalid');
	}
	
	if (!parent_permission.attr("checked")){
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		$("#sp_parent_permission").addClass('invalid');
		parent_permission.focus();
	}
	else
	{
		$("#sp_parent_permission").removeClass('invalid');
	}
	
	if(email.val() == "") {
		errorText = "Please fill mandatory fields";
		mand_flag = 0;
		email.addClass('invalid');
		email.focus();
	}
	else
	{
		if (email.val().search(emailRegxp)== -1) {
			errorText += (errorText != "" ? "<br/>" : "") + "Your email is invalid";
			mand_flag = 0;
			email.addClass('invalid');
			email.focus();
		}
		else
		{
			email.removeClass('invalid');
		}
	}
	
	if(studentemail.val() != "")	
	{
		if (studentemail.val().search(emailRegxp)== -1) {
			errorText += (textError != "" ? "<br/>" : "") + "Your student email is invalid";
			mand_flag = 0;
			studentemail.addClass('invalid');
			studentemail.focus();
		}
		else
		{
			studentemail.removeClass('invalid');
		}
	}
	else
	{
		studentemail.removeClass('invalid');
	}
	
	if(passwd_rem.val() != "")
	{
		if ( passwd_rem.val() != passwd.val()) {
			errorText += (errorText != "" ? "<br/>" : "") + "Your password and retype password don't match";
			mand_flag = 0;
			passwd_rem.addClass('invalid');
			passwd_rem.focus();
		}
		else if (passwd.val().length < 6)
		{
			errorText += (errorText != "" ? "<br/>" : "") + "Your password length must be greater than or equal 6 characters";
			mand_flag = 0;
			passwd.addClass('invalid');
			passwd.focus();
		}
	}
	
	if(mand_flag == 0) {
		$('#error_msg').html(errorText).fadeIn();
	}
	else		
	{
		$('#error_msg').html("").hide();
		$('#process').val('add_user');	
		document.reg_user.method="post";			
		document.reg_user.action="application/action.php";
		document.reg_user.submit();		
	}	
	
	return false;
}

function validateReg_box()
{
	var name = $('#fname').val();
	var passwd = $('#passwd').val();
    var email = $('#email_val').val();
	var studentemail = $('#studentemail_val').val();
	var security_code = $('#security_code').val();
	
	
	var flag = true;
	if(!name) {	$('#fname').addClass('mandatory_field1'); flag = false;	}
	if(!passwd) { $('#passwd').addClass('mandatory_field1');  flag = false; }
	if(!email ||  email.search(emailRegxp)== -1) { $('#email_val').addClass('mandatory_field1'); flag = false;	}
	//if(!studentemail ||  studentemail.search(emailRegxp)== -1) { $('#studentemail_val').addClass('mandatory_field1'); flag = false;	}
	if(!security_code) { $('#security_code').addClass('mandatory_field1'); flag = false;	}
	if ($('#parent_permission').attr('checked') == false ) {
		$('#per').addClass('mandatory_field1'); flag = false;
}
	
	if(!flag) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('All fields with Red tar Are Mandatory');
		$('#error_msg').fadeOut(3000);
		
	}
	if(flag) {
		
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		} else {
		
			document.reg_user_box.method="post";
			document.reg_user_box.action="application/action.php";
			document.reg_user_box.submit();
		}
	}
	return false;
}
/*
function SaveAssignmentToAccount(frmName) {
	var frm = document.forms[frmName];
	if(frm) {
		if (confirm('Are you sure to save your assignment for doing later?'))
		{
			frm.method = "POST";
			frm.action = "http://localhost:8080/aw/application/savetoaccount.php";
			//frm.action = "http://www.studysage.com.au/application/savetoaccount.php";
			frm.submit();
		}
	}
}
*/

function ForValidate()
{
	
	var email = $('#email').val();
		
	var mand_flag = 1;


	if(email == "") {
		mand_flag = 0;
		$('#email').addClass('mandatory_field');
	}
	

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('E mail id Required');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
			$('#process').val('forgetid');	
			document.forpas.method="post";
			
			document.forpas.action="application/action.php";
			document.forpas.submit();
		}
	}
	return false;
}


function signin()
{	
	var email = $('#email');
	var password = $('#password');
	var mand_flag = 1;
	var textError = "";
	
	if(password.val() == "") {
		textError = "Please fill mandatory fields";
		mand_flag = 0;
		$('#password').addClass('invalid');
		$('#email').focus();
	}
	else
	{
		$('#password').removeClass('invalid');
	}
	
	if(email.val() == "") {
		textError = "Please fill mandatory fields";
		mand_flag = 0;
		$('#email').addClass('invalid');
		$('#email').focus();
	}
	else
	{
		if (email.val().search(emailRegxp)== -1) {
			textError += (textError != "" ? "<br/>" : "") + "Your email is invalid";
			mand_flag = 0;
			$('#email').addClass('invalid');
			$('#email').focus();
		}
		else
		{
			$('#email').removeClass('invalid');
		}
	}	
	

	if(mand_flag == 0) {		
		$('#error_msg').html(textError).fadeIn();		
	}
	else
	{
		$('#error_msg').html("").hide();
		$('#process').val('log');
		document.login.method="post";
		document.login.action="application/action.php";
		document.login.submit();
	}
	
	/*
	if(mand_flag == 1) {
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
		
			$('#process').val('log');	
			
			document.login.method="post";
			document.login.action="application/action.php";
			document.login.submit();
		}
	}
	*/
	return false;
}

function validateContact()
{
	var isValid = true;
	var email = $('#email');
	var name = $('#name');	
	var securitycode = $('#securitycode');
	var errorText = "";
	
	if(name.val() == "") {
		errorText = "Please fill mandatory fields";
		$('#name').addClass("invalid");
		$('#name').focus();
		isValid = false;
	}
	else
	{
		$('#name').removeClass("invalid");
	}
	
	if(securitycode.val() == "") {
		errorText = "Please fill mandatory fields";
		$('#securitycode').addClass("invalid");		
		$('#securitycode').focus();		
		isValid = false;
	}
	else
	{
		$('#securitycode').removeClass("invalid");
	}
		
	if(email.val() == "") {
		errorText = "Please fill mandatory fields";
		$('#email').addClass("invalid");
		isValid = false;
	}
	else {		
		var valid_email_address = /[\S]+@[\S]+\.[\w]{2}/;
		if(email.val().search(valid_email_address )== -1) {		
			errorText += (errorText != "" ? "<br/>"  : "") + "Your email is invalid";
			isValid = false;
		}
		else
		{
			$('#email').removeClass("invalid");
		}
	}
	
	if (isValid)
	{
		$('#error_msg').html("").hide();
		$('#process').val('add_contact');	
		$("#form_action").val("action");		
		document.contact.action = "application/action.php";
	}
	else
	{
		$('#error_msg').html(errorText).fadeIn();
	}
	
	return isValid;
	/*
	$('#process').val('add_contact');	
	$("#form_action").val("action");
	document.contact.action = "application/action.php";
	document.contact.submit();	
	
	if (!isValid){
		$('#error_msg').fadeIn();
	}
	*/
	/*
	$.post("application/action.php",{ process:'add_contact', vendor_id:vendor_id },function(getResult){
		if(getResult == 1) {
			$("#mail_img_"+vendor_id).attr("src", server_path+'public/images/mail_enable.png');
		}
		else {
			$("#mail_img_"+vendor_id).attr("src", server_path+'public/images/mail_disable.png');
		}
	});
	*/
}

function ValidateForm1()
{
	
	var title = $('#title').val();
	var desc = $('#desc').val();
	var searchtittle = $('#searchtittle').val();
	var summary = $('#summary').val();
	var cdate = $('#cdate').val();
	var cname = $('#cname').val();
	var email = $('#email').val();
	
	
	var mand_flag = 1;


	if(title == "") {
		mand_flag = 0;
		$('#title').addClass('mandatory_field');
	}
	
	if(desc == "") {
		mand_flag = 0;
		$('#desc').addClass('mandatory_field');
	}
	if(searchtittle == "") {
		mand_flag = 0;
		$('#searchtittle').addClass('mandatory_field');
	}
	if(summary == "") {
		mand_flag = 0;
		$('#summary').addClass('mandatory_field');
	}
	if(cdate == "") {
		mand_flag = 0;
		$('#cdate').addClass('mandatory_field');
	}
	if(cname == "") {
		mand_flag = 0;
		$('#cname').addClass('mandatory_field');
	}
	if(email == "") {
		mand_flag = 0;
		$('#email').addClass('mandatory_field');
	}

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
			if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
			document.theForm.method="post";
			document.theForm.submit();
		}
	}
	return false;
}
function ValidateForm2()
{
	
	var Category = $('#Category').val();
	var txtHint1 = $('#txtHint1').val();
	var searchtittle = $('#searchtittle').val();
	var summary = $('#summary').val();
	var location = $('#location').val();
	var worktype = $('#worktype').val();
	
	
	var mand_flag = 1;


	if(Category == 0) {
		mand_flag = 0;
		$('#Category').addClass('mandatory_field');
	}
	
	if(txtHint1 == 0) {
		mand_flag = 0;
		$('#txtHint1').addClass('mandatory_field');
	}
	if(searchtittle == "") {
		mand_flag = 0;
		$('#searchtittle').addClass('mandatory_field');
	}
	if(summary == "") {
		mand_flag = 0;
		$('#summary').addClass('mandatory_field');
	}
	if(location == 0) {
		mand_flag = 0;
		$('#location').addClass('mandatory_field');
	}
	if(worktype == 0) {
		mand_flag = 0;
		$('#worktype').addClass('mandatory_field');
	}

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		
			document.thisForm.method="post";
			document.thisForm.submit();
		}
	
	return false;
}

function apply_job()
{
	
	var my_name = $('#my_name').val();
	
	var email = $('#my_email').val();
	
	var attach = $('#attach').val();
		
	var mand_flag = 1;


	if(my_name == "") {
		mand_flag = 0;
		$('#my_name').addClass('mandatory_field');
	}
	if(email == "") {
		mand_flag = 0;
		$('#my_email').addClass('mandatory_field');
	}
	if(attach == "") {
		mand_flag = 0;
		$('#attach').addClass('mandatory_field');
	}
	
	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
			if(email != "" && email.search(emailRegxp)== -1) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter a valid email address ');
		$('#error_msg').fadeOut(3000);
			
			$('#email').focus();
		}
		var checkimg = attach.toLowerCase();
		if (attach != "" && !checkimg.match(/(\.doc|\.docx|\.pdf|\.DOC|\.DOCX|\.PDF)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select DOC,DOCX or PDF Files");
			$('#my_resume').focus();
			
		}
		
		else {
			$('#process').val('sendjobmail');	
	        document.applyjob.action = "application/action.php";
			document.applyjob.method="post";
			document.applyjob.submit();
		}
	}
	return false;
}

function validateBannerAdverts()
{
	var email = $('#email').val();
	var name = $('#name').val();
	var advt_item = $('#advt_item').val();
	var advt_days = $('#advt_days').val();
	
	//var mand_flag = 1;


	if(email == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the eMail Address');
		$('#error_msg').fadeOut(3000);
		$('#email').focus();
		return false;
	}
	else {
		
		var valid_email_address = /[\S]+@[\S]+\.[\w]{2}/;
		if(email.search(valid_email_address )== -1) {
		
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please enter the valid eMail Address");
			$('#error_msg').fadeOut(3000);
			$('#email').focus();
			return false;
		}	
	}
	
	if(name == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Name');
		$('#error_msg').fadeOut(3000);
		$('#name').focus();
		return false;
	}
	
	if(advt_item == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Adverts Item');
		$('#error_msg').fadeOut(3000);
		$('#advt_item').focus();
		return false;
	}
	
	if(advt_days == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Adverts Run Time');
		$('#error_msg').fadeOut(3000);
		$('#advt_days').focus();
		return false;
	}
	
	if($('#read_terms').attr('checked') == false) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Accept our terms and agreement');
		$('#error_msg').fadeOut(3000);
		return false;		
	}
	
	$('#process').val('add_query');	
	document.contact.action = "application/action.php";
	document.contact.submit();	
}
function validateproduct()
{
	
	var gadget = $('#gadget').val();
	var make = $('#make').val();
	var spec = $('#spec').val();
	var Quality = $('#Quality').val();
	var price = $('#price').val();
	var upload = $('#upload').val();
	
	var mand_flag = 1;


	if(gadget == 0) {
		mand_flag = 0;
		$('#gadget').addClass('mandatory_field');
		
	}
	
	if(make == "") {
		mand_flag = 0;
		$('#make').addClass('mandatory_field');
	}
	if(spec == "") {
		mand_flag = 0;
		$('#spec').addClass('mandatory_field');
	}
	if(Quality == 0) {
		mand_flag = 0;
		$('#Quality').addClass('mandatory_field');
	}
	if(price == "") {
		mand_flag = 0;
		$('#price').addClass('mandatory_field');
	}
	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		var checkimg = upload.toLowerCase();
		if (upload != "" && !checkimg.match(/(\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG|\.GIF|\.gif)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select JPG,GIF or PNG File");
			$('#error_msg').fadeOut(3000);
			$('#upload').focus();
			
		}
	else
	{
		
	$('#process').val('sellproduct');	
	        document.product.action = "application/action.php";
			document.product.method="post";
			document.product.submit();
		
	}}
	return false;
}

function sellbooks()
{
	
	var tit = $('#tit').val();
	var author = $('#author').val();
	var desc = $('#desc').val();
	var isbn = $('#isbn').val();
	var price = $('#price').val();
	var upload = $('#upload').val();
	
	var mand_flag = 1;

	if(tit == "") {
	mand_flag = 0;
	$('#tit').addClass('mandatory_field');
	}
		
	if(author == "") {
	mand_flag = 0;
	$('#author').addClass('mandatory_field');
	}
	if(desc == "") {
	mand_flag = 0;
	$('#desc').addClass('mandatory_field');
	}
	if(isbn == "") {
	mand_flag = 0;
	$('#isbn').addClass('mandatory_field');
	}
	if(price == "") {
	mand_flag = 0;
	$('#price').addClass('mandatory_field');
	}
	
	if(mand_flag == 0) {
	$('#error_msg').fadeIn(3000);
	$('#error_msg').html('* Marked fields are Required ');
	$('#error_msg').fadeOut(3000);
	}
	
	if(mand_flag == 1) {
		var checkimg = upload.toLowerCase();
		if (upload != "" && !checkimg.match(/(\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG|\.GIF|\.gif)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select JPG,GIF or PNG File");
			$('#error_msg').fadeOut(3000);
			$('#upload').focus();
			
		}
	else
	{
		$('#process').val('sellbook');	
	
	       document.sellbook.action = "application/action.php";
			document.sellbook.method="post";
			document.sellbook.submit();
		
	}}
	return false;
}
		
function validateSearch()
{
	var txt_search = $('#txt_search').val();

	if(txt_search != "" && txt_search != 'search') {
		document.frmSearch.method="post";
		document.frmSearch.action="index.php?page=search";
		document.frmSearch.submit();	
	}
	
	return false;
}	
function vote(eid)
{
	
	var val = document.vote_form.univ_id.value=eid;
	document.vote_form.action = "application/action.php";
	document.vote_form.method="post";
	document.vote_form.submit();
}	

		
	